if(!jsx3.lang.Class.forName("ux.cdb.admin.customer.cusBuilder.BaseInfo")) {
	jsx3.lang.Class.defineClass("ux.cdb.admin.customer.cusBuilder.BaseInfo",
			ux.megatron.gui.WizardPanel,
			null,
			function (block) {
				
				var genObject = function(obj){
					var result = {};
					for(var prop in obj){
						result[prop] = obj[prop];
					}
					return result;
				}
				
				/**
				 * instance initializer
				 * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
				 * @param vntLeft {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntTop {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntWidth {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntHeight {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param strHTML {String} Text/HTML markup to place in the jsx3.gui.Block instance
				 */
				block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
					//call constructor for super class (the super expects the name of the object and the function that it is an instance of)
					this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
				};

				block.prototype.initialize = function(msg) {
					this.loaded = true;
					this.builder = this.getAncestorOfType("ux.cdb.admin.customer.cusBuilder.Builder");
					this.wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
					this.bEdit = false;
					this.certId = this.get('blkCertId').getChild(1);

/* @JSC :: begin DEBUG */
					jsx3.log("initialize studentId: " + this.builder.studentId);
/* @JSC :: end */
					if(this.builder.studentId) {
						this.bEdit = true;
						this.builder.editMode = 'edit';
						ux.megatron.util.Dwr.callDwr("AddStudentInfoUCC", "getStudentAllInfoByIdForUpdate", 
                			[this.builder.studentId], this, function(obj) {
                			//console.log("Customer#BaseInfo getStudentAllInfoByIdForUpdate : \n" , obj.content.data);
/* @JSC :: begin DEBUG */
							jsx3.log(dwr.util.toDescriptiveString(obj.content.data,4));
/* @JSC :: end */
                			this.builder.baseInfo = obj.content.data[0] || {};
/* @JSC :: begin DEBUG */
 							jsx3.log(dwr.util.toDescriptiveString(this.builder.baseInfo,4));
/* @JSC :: end */
	               			this.builder.studyInfo = obj.content.data[1] || {};
                			this.builder.accInfo = obj.content.data[2] || {};
                			this.builder.careerInfo = obj.content.data[3] || {};
                			
                			//this.builder.dataBag = obj.content.data[0];
                    		this.getDescendantsOfType("ux.cdb.admin.dataautomate.GenericDetail")[0].setDataByObject(this.builder.baseInfo);
               			});
						
					} else {
						delete this.buttonStatesArr;
                        this.buttonStates="buttonPrev:DISABLED,buttonFinish:DISABLED";
						this.wizard.get("buttonFinish").disable();
						
						this.builder.baseInfo = {};
						this.builder.studyInfo = {};
						this.builder.accInfo = {};
						this.builder.careerInfo = {};
						
						var me = this;
						setTimeout(function(){
							var defaultProvince = ux.cdb.admin.Privilege.getProvinceCode();
							if(defaultProvince.indexOf('0') > 0){
								var _p1 = defaultProvince.substring(0,2);
								var _p2 = defaultProvince.substring(2,4);
								var _p3 = defaultProvince.substring(4,6);
								var __province = _p1 + (_p2 != '00' ? _p2 : '01') + _p3;
/* @JSC :: begin DEBUG */
								jsx3.log('defaultProvince : ' + defaultProvince + ' __province : ' + __province);
/* @JSC :: end */
								var areas = me.getDescendantsOfType('ux.cdb.admin.dataautomate.AreaUpdater');
								/**/
								areas[0].setDataByObject({countyCode2: defaultProvince});
								areas[1].setDataByObject({countyCode1: defaultProvince});
								areas[2].setDataByObject({countyCode3: defaultProvince});
								
								/* for(var i=0;i<areas.length;i++){
									//areas[i].getDescendantOfName("selValue1").setValue(defaultProvince);
									//areas[i].onSelectChanged();
									//areas[i].getChild(2).setValue(defaultProvince);
									//areas[i].getChild(3).setValue(__province);
									//me.setDefaultRecord(areas[i].getChild(2));
									//me.setDefaultRecord(areas[i].getChild(3));
								} */
							}
						},0);
					}
					
				}

				block._defaultText = ux.megatron.Main.getServer().getDynamicProperty("@cdb@Select Default Text");
				block.prototype.setDefaultRecord = function(sel) {
					var _sourceCDF = sel.getXML();
					var _topjsxid = _sourceCDF.getFirstChild().getAttribute('jsxid');
					_sourceCDF.insertRecordBefore({jsxid:'', jsxtext:block._defaultText, jsxstyle:'width:100%;'}, _topjsxid);
					sel.setSourceXML(_sourceCDF);
					sel.setValue('', true);
				}
				
				block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return this.doValidation() ? null : 'NONE';
				}

				block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not last status
				}

				block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					this.getAncestorOfType("ux.cdb.admin.customer.cusBuilder.Builder").onClose();
					return null;
				}
				
				block.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
                    if(this.doValidation()) { this.builder.saveBuilder(); }
                    return "NONE";
				};

				block.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
					if(!this.getChild(0)) {
						var me = this;					
						ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/customer/cusBuilder/step1/ui/baseInfoContent.xml", me, me.initialize);
					}
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {

					return null; // return "NONE" to not advance panels
				}
				
				block.prototype.onStepJump =  function(objWIZARD,objSTEP,objEVENT,strCURRENTPANEL){
					return this.doValidation() ? null : 'NONE';
				};
				
				block.prototype.displayTip = function(passed) {
                    if(!passed) {
                        var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@cusbuilder@TipUnFinishedStep1");
                        this.wizard.getMessageLabel().setText(this._message ? this._message : tip,true);
                    } else {
                        this.wizard.getMessageLabel().setText("",true);
                    }
                    return passed;
                };
				
				block.prototype.doValidation = function() {
                    this.detail = this.get("blkStep1");
					var errorMsgs = this.detail.doValidate();
                    this._message = errorMsgs === null ? null : (errorMsgs[0].label ? errorMsgs[0].label + " : " +errorMsgs[0].message : errorMsgs[0].message);
                    if(this._message === null) {
                    	this.cacheDataobj();
	    				return this.displayTip(true);
                    } else {
                        return this.displayTip(false);
                    }
                };
                
                block.prototype.cacheDataobj = function () {
                	//function to split area code 
					var rearrange = function(str,attArr){
						var obj = {};
						obj[attArr[0]] = str.substring(0,2); 
						obj[attArr[1]] = str.substring(2,4); 
						obj[attArr[2]] = str;//str.substring(4,6); 
						return obj;
					}
					//populate data
					var dataObj =  this.detail.getDataAsObject();
					var areaCodes = rearrange(dataObj['nowAddressCode'],['provinceCode1','regionCode1','countyCode1']);
					this.extendObj(dataObj,areaCodes);
					areaCodes = rearrange(dataObj['beforeAddressCode'],['provinceCode2','regionCode2','countyCode2']);
					this.extendObj(dataObj,areaCodes);
					areaCodes = rearrange(dataObj['familyAddressCode'],['provinceCode3','regionCode3','countyCode3']);
					this.extendObj(dataObj,areaCodes);
					
					//this.builder.cacheInfo(dataObj);
					this.extendObj(this.builder.baseInfo,dataObj);
                };
				
				block.prototype.extendObj = function(tarObj,orgObj){
					for(var prop in orgObj){
						tarObj[prop] = orgObj[prop];
					}
					return tarObj;
				};
				
                block.prototype.setBirthday = function () {
					if(!this.checkStuCertId()) return;
					var certId = this.get('blkCertId').getDescendantOfName('txtValue').getValue();
/* @JSC :: begin DEBUG */
					jsx3.log('Customer#BaseInfo#setBirthday certId : ' + certId);
/* @JSC :: end */
					if(certId){
		                var birthday = this.get('blkBirthDate').getChild(1);
						var date = new Date();
						if(certId.length == 18){
							var year = certId.substring(6,10);
							var month = certId.substring(10,12);
							var day = certId.substring(12,14);
							date.setFullYear(year, month - 1, day);
						}else if(certId.length == 15){
							var year = certId.substring(6,8);
							var month = certId.substring(8,10);
							var day = certId.substring(10,12);
							date.setFullYear('19' + year, month - 1, day);
						}
/* @JSC :: begin DEBUG */
						jsx3.log('Customer#BaseInfo#setBirthday year['+year+'],month['+month+'],day['+day+'].');
/* @JSC :: end */
						birthday.setDate(date);
					}
				};
                
                block.prototype.checkStuCertId = function () {
                	this.detail = this.get("blkStep1");
					var flag = this.get('blkCertId').doValidate() === null;
					if(!flag) this.get('blkCertId').getChild(1).focus();
					return flag;
/* @JSC :: begin DEBUG */
                	jsx3.log('Customer#BaseInfo#checkStuCertId certId : ' + this.certId);
/* @JSC :: end */
                	if(!this.bEdit) {
						ux.megatron.util.Dwr.callDwr("AddStudentInfoUCC", "getStudentListByCondition", 
                			[null, this.certId, null, 0, 0], this, function(obj) {
                			if(obj.content.data != null && obj.content.data.length > 0) {
                				this.bEdit = true;
                				this.builder.editMode = 'edit';
	                			this.extendObj(this.builder.baseInfo,obj.content.data[0]);
	                    		this.getDescendantsOfType("ux.cdb.admin.dataautomate.GenericDetail")[0].setDataByObject(obj.content.data[0]);
	                    		
	                    		this.wizard.addStep(3, 
									"ux/cdb/admin/customer/cusBuilder/step1/ui/step4step.xml", 
									"ux/cdb/admin/customer/cusBuilder/step4/ui/careerInfo.xml", 
									"ux.cdb.admin");
								this.wizard.resetNumber();
								this.builder.get('windowBar').setText(ux.megatron.Main.getServer().getDynamicProperty('@cdb@cusbuilder@edittitle'), true);
								this.get('blkCertId').getDescendantOfName('label').setText(ux.megatron.Main.getServer().getDynamicProperty('@cdb@@cusbuilder@stuExist'), true);
							} 
               			});
					}
				}
                
			}
	);
}
